//
//  NWVisitorTableViewController.swift
//  Weibo
//
//  Created by Northwan on 16/1/20.
//  Copyright © 2016年 Northwan. All rights reserved.
//

import UIKit

class NWVisitorTableViewController: UITableViewController {
    
    var userlogon = NWUserAccountViewModel.sharedAccount.userLogon
    
    override func loadView() {
        userlogon ? super.loadView() : setupVisitorView()
    }
    
    private func setupVisitorView(){
        view = visitorView;
        
        visitorView.registerButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
        visitorView.loginButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
        // 设置左右的登录注册按钮
        setupUI()
    }
    
    private func setupUI(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "login")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "login")
    }
    
    @objc private func login(){
        // 执行登录
        presentViewController(NWNavigationController(rootViewController: NWOauthViewController()), animated: true, completion: nil)
    }
    
    
    // MARK: - 懒加载控件
    lazy var visitorView:NWVisitorView = {
        let visitorView = NWVisitorView()
        return visitorView
    }()
    
}
